package com.company.ThreadDemo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 作者：13687
 * 日期：2017/6/4
 * 项目：ThreadPoolsDemo
 * 描述：把任务交给线程池
 */
public class ThreadDemo3 {
	public static void main(String[] args) {
		// 只开一个线程
		ExecutorService es = Executors.newSingleThreadExecutor();
		CountRunnable work = new CountRunnable();
		es.execute(work);
		es.shutdown();//关闭线程池|如果不关闭程序就不会执行结束
		System.out.println("任务结束"+es.isShutdown());
	}
	public static class CountRunnable implements Runnable{
		private int sum;
		@Override
		public void run() {
			for(int i=1 ; i<11 ; i++){
				sum+=i;
			}
			System.out.println("sum="+sum);
		}
	}
}
